﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Lawyer.Web.Admin
{
    public partial class admin_password : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserID"] == null)
            {
                Response.Redirect("admin_userlist.aspx");
            }
            if (!IsPostBack)
            {
                BindData();
            }
        }

        private void BindData()
        {
            string ID = Session["UserID"].ToString();
            Lawyer.BLL.UserInfo bll = new Lawyer.BLL.UserInfo();
            Lawyer.Model.UserInfo model = bll.GetModelFromUserID(ID);
            if (model == null)
            {
                Response.Redirect("admin_userlist.aspx");
            }
            txbUserName.Text = model.UserName;
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string ID = Session["UserID"].ToString();
            Lawyer.BLL.UserInfo BLL = new Lawyer.BLL.UserInfo();
            Lawyer.Model.UserInfo model = BLL.GetModelFromUserID(ID);
            if (model == null)
            {
                Response.Redirect("admin_userlist.aspx");
            }
            if (txbOldPassword.Text != model.Password) {
                Maticsoft.Common.MessageBox.Show(this,"The old password is not correct!");
                return;
            }
            if (txbPassword.Text != txbPassConf.Text)
            {
                Maticsoft.Common.MessageBox.Show(this, "The new password is not match!");
                return;
            }
            model.Password = txbPassword.Text.Trim();
            if (BLL.Update(model))
            {
                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "success!", "admin_userlist.aspx");
                return;
            }
            else {
                Maticsoft.Common.MessageBox.Show(this, "failed!");
                return;
            }
        }
    }
}
